﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace SimplexEngine
{
    public class SpriteManager
    {
        // name generator
        protected static NameGenerator name_generator = new NameGenerator("Sprite");

        public virtual void Update(GameTime game_time, Int64 frame_number)
        {            
        }

        public virtual void Draw(RenderSystem render_system, GameTime game_time, Int64 frame_number)
        {
            if (sprites.Count == 0)
                return;

            SpriteBatch sprite_batch = render_system.SpriteBatch;
            sprite_batch.Begin();
            foreach (Sprite sprite in sprites.Values)
                sprite.Draw(sprite_batch);
            sprite_batch.End();
        }

        public virtual void AddSprite(String name, Sprite sprite)
        {
            sprites.Add(name, sprite);
        }

        public virtual void AddSprite(Sprite sprite)
        {
            AddSprite(name_generator.Generate(), sprite);
        }

        public Sprite GetSprite(String name)
        {
            return sprites[name];
        }

        public void RemoveSprite(String name)
        {
            sprites.Remove(name);
        }

        public void RemoveAll()
        {
            sprites.Clear();
        }

        protected Dictionary<String, Sprite> sprites = new Dictionary<String, Sprite>();
    }
}
